<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<f:view>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title>Global Image - Criar nova Venda</title>
            <link rel="stylesheet" type="text/css" href="/globalimage2/faces/jsfcrud.css" /><%@ include file="/WEB-INF/jspf/AjaxScripts.jspf" %><script type="text/javascript" src="/globalimage2/faces/jsfcrud.js"></script>
        </head>
        <body>
            <%@include file="../../WEB-INF/jspf/header/head.jspf"%>
            <div style="float:left">
                <%@include file="../../WEB-INF/jspf/header/menuDinamico.jspf"%>
            </div>
            <div id="div_content">
                <div class="bgContentTable">
                    <div class="titleTable"><h3>Criar nova Venda</h3></div><br />
                    <h:form>
                        &nbsp;&nbsp;<h:commandLink action="#{venda.create}" value="Salvar"/>
                        &nbsp;|&nbsp;
                        <h:commandLink action="#{venda.listSetup}" value="Cancelar" immediate="true"/>
                        

                        <h:panelGroup id="messagePanel" layout="block">
                            <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                        </h:panelGroup>
                        <br />
                        <h:inputHidden id="validateCreateField" validator="#{venda.validateCreate}" value="value"/>
                        <h:panelGrid columns="2" style="margin-left:10px;">
                            <h:outputText value="Cliente:"/>
                            <h:selectOneMenu id="clienteId" value="#{venda.venda.clienteId}" title="ClienteId" required="true" requiredMessage="The clienteId field is required." >
                                <f:selectItems value="#{usuario.usuarioItemsAvailableSelectOneOnlyCliente}"/>
                            </h:selectOneMenu>
                            <h:outputText value="Vendedor:"/>
                            <h:selectOneMenu id="funcionarioId" value="#{venda.venda.funcionarioId}" title="FuncionarioId" required="true" requiredMessage="The funcionarioId field is required." >
                                <f:selectItems value="#{funcionario.funcionarioItemsAvailableSelectOne}"/>
                            </h:selectOneMenu>
                            <h:outputText value="Descrição:"/>
                            <h:inputTextarea rows="4" cols="30" id="observacao" value="#{venda.venda.observacao}" title="Observacao" />
                            <h:outputText value="Data da venda:"/>
                            <h:panelGrid columns="3">
                                <h:selectOneMenu id="diaVenda" value="#{venda.funcionarioDiaDataVenda}">
                                    <f:selectItems value="#{utilController.arrayDias}"/>
                                </h:selectOneMenu>
                                <h:selectOneMenu id="mesVenda" value="#{venda.funcionarioMesDataVenda}">
                                    <f:selectItems value="#{utilController.arrayMeses}"/>
                                </h:selectOneMenu>
                                <h:selectOneMenu id="anoVenda" value="#{venda.funcionarioAnoDataVenda}">
                                    <f:selectItems value="#{utilController.arrayAnos}"/>
                                </h:selectOneMenu>
                            </h:panelGrid>
                            <h:outputText value="Data de entrega:"/>
                            <h:panelGrid columns="3">
                                <h:selectOneMenu id="diaEntrega" value="#{venda.funcionarioDiaDataEntrega}">
                                    <f:selectItems value="#{utilController.arrayDias}"/>
                                </h:selectOneMenu>
                                <h:selectOneMenu id="mesEntrega" value="#{venda.funcionarioMesDataEntrega}">
                                    <f:selectItems value="#{utilController.arrayMeses}"/>
                                </h:selectOneMenu>
                                <h:selectOneMenu id="anoEntrega" value="#{venda.funcionarioAnoDataEntrega}">
                                    <f:selectItems value="#{utilController.arrayAnos}"/>
                                </h:selectOneMenu>
                            </h:panelGrid>
                            <h:outputText value="Primeira parcela:"/>
                            <h:panelGrid columns="3">
                                <h:selectOneMenu id="diaPagamento" value="#{venda.funcionarioDiaDataPagamento}">
                                    <f:selectItems value="#{utilController.arrayDias}"/>
                                </h:selectOneMenu>
                                <h:selectOneMenu id="mesPagamento" value="#{venda.funcionarioMesDataPagamento}">
                                    <f:selectItems value="#{utilController.arrayMeses}"/>
                                </h:selectOneMenu>
                                <h:selectOneMenu id="anoPagamento" value="#{venda.funcionarioAnoDataPagamento}">
                                    <f:selectItems value="#{utilController.arrayAnos}"/>
                                </h:selectOneMenu>
                            </h:panelGrid>
                            <h:outputText value="Transportador:"/>
                            <h:selectOneMenu id="transportadorId" value="#{venda.venda.transportadorId}" title="TransportadorId" >
                                <f:selectItems value="#{usuario.usuarioItemsAvailableSelectOneOnlyTransportador}"/>
                            </h:selectOneMenu>
                            <h:outputText value="Valor Transporte:"/>
                            <h:inputText id="valorTransporte" value="#{venda.venda.valorTransporte}" title="ValorTransporte">
                                <f:convertNumber type="currency"/>
                            </h:inputText>
                            <h:outputText value="Seguro Transporte:"/>
                            <h:inputText id="seguroTransporte" value="#{venda.venda.seguroTransporte}" title="SeguroTransporte">
                                <f:convertNumber type="currency"/>
                            </h:inputText>

                            <h:outputText value="Outros:"/>
                            <h:selectOneMenu id="addOperacaoExtraAction" value="#{venda.operacao}" valueChangeListener="#{venda.addOperacaoExtraAction}" onchange="submit();" immediate="true" required="false">
                                <f:selectItems value="#{operacaoExtraTipo.operacaoExtraTipoItemsAvailableSelectOne}"/>
                            </h:selectOneMenu>
                            <h:outputText value=" "/>
                                <h:dataTable rendered="#{not empty venda.venda.opercaoExtraCollection}" value="#{venda.venda.opercaoExtraCollection}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px;width: 98%; margin-left: 10px;">
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Nome"/>
                                        </f:facet>
                                        <h:outputText value=" #{item}"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Valor"/>
                                        </f:facet>
                                        <h:inputText value="#{item.valor}" title="Valor"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value=" "/>
                                        </f:facet>
                                        <h:commandLink value="Remover" action="#{venda.removerOperacaoExtra}" immediate="true">
                                            <f:param name="jsfcrud.currentOpercaoExtra" value="#{jsfcrud_class['entidade.controller.JSF.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][item.operacaoExtraTipoId][operacaoExtraTipo.converter].jsfcrud_invoke}"/>
                                        </h:commandLink>
                                    </h:column>
                                </h:dataTable>
                        </h:panelGrid>

                        &nbsp;<h:commandLink action="#{produto.listVendaSetup}" value="Adicionar produto"  style="margin-left:10px;"/><br />

                        <c:if test="${venda.venda.produtoVendaCollection != null}">
                            <br/>
                            <h:panelGroup style="margin-left:10px;">
                                &nbsp;<h:outputText value="Produtos:"/>
                                <h:dataTable value="#{venda.venda.produtoVendaCollection}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px;width: 98%; margin-left: 10px;">
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Nome"/>
                                        </f:facet>
                                        <h:outputText value=" #{item.produto.nome}"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Quantidade"/>
                                        </f:facet>
                                        <h:selectOneMenu value="#{item.quantidade}" title="Quantidade" valueChangeListener="#{venda.calcularParcelas_comboQtdProd}" onchange="javascript:submit();">
                                            <f:selectItems value="#{utilController.array_1_to_50}"/>
                                        </h:selectOneMenu>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Preço unitário"/>
                                        </f:facet>
                                        <h:inputText value="#{item.precoUnitario}" size="9" maxlength="20" >
                                            <f:convertNumber type="currency"/>
                                        </h:inputText>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value=""/>
                                        </f:facet>
                                        <h:commandLink value="Remover" action="#{venda.removerProdutoVenda}" immediate="true">
                                            <f:param name="jsfcrud.currentProduto" value="#{jsfcrud_class['entidade.controller.JSF.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][item.produto][produto.converter].jsfcrud_invoke}"/>
                                        </h:commandLink>
                                    </h:column>
                                </h:dataTable>
                                <br/>
                                <br/>
                                <h:panelGrid columns="5" style="margin-left:10px;">
                                    <h:outputText value="Parcelas:"/>
                                    <h:inputText id="parcelas" value="#{venda.qtdParcelas}" title="Parcelas" size="3" maxlength="3"
                                                 valueChangeListener="#{venda.calcularParcelas_txtQtdParcelas}" onchange="javascript:submit();"/>
                                    <h:outputText value="Juros ao mês:"/>
                                    <h:inputText id="jurosMes" value="#{venda.venda.jurosMes}" title="Juros" size="5" maxlength="5"
                                                 valueChangeListener="#{venda.calcularParcelas_txtJurosMes}" onchange="javascript:submit();">
                                        <f:convertNumber type="percent"/>
                                    </h:inputText>
                                    <h:commandLink action="#{venda.calcularParcelas}" value="Calcular Parcelas"/>
                                </h:panelGrid>
                            </h:panelGroup>
                            <c:if test="${venda.parcelaVenda != null}"   >
                                <h:dataTable value="#{venda.parcelaVenda}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px; width:98%;margin-left:10px;">
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Parcela(s)"/>
                                        </f:facet>
                                        <h:outputText value="#{item.numParcelaFormatado}"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Pagamento"/>
                                        </f:facet>
                                        <h:outputText value="#{item.dataParcela}">
                                            <f:convertDateTime pattern="dd/MM/yyyy" />
                                        </h:outputText>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="Valor"/>
                                        </f:facet>
                                        <h:inputText value="#{item.valorParcela}">
                                            <f:convertNumber type="currency"/>
                                        </h:inputText>
                                    </h:column>
                                </h:dataTable>
                            </c:if>
                            <h:panelGrid columns="2" style="margin-left:10px;">
                                <h:outputText value="Total:"/>
                                <h:outputText value="#{venda.venda.totalVenda}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </h:panelGrid>
                        </c:if>
                    </h:form>
                </div>
            </div>
        </body>
    </html>
</f:view>
